package com.financing.platform.service.impl;

import java.sql.SQLException;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.financing.platform.dao.ICompanyDao;
import com.financing.platform.dto.CompanyDTO;
import com.financing.platform.dto.CompanyInvitationCodeDTO;
import com.financing.platform.service.ICompanyService;

/**
 * 
* @ClassName: OrderServiceImpl 
* @Description: 机构管理
* @author chenming 
* @date 2014年8月18日 下午2:42:30 
*
 */
@Service("companyServiceImpl")
@Transactional(rollbackFor=Exception.class)
public class CompanyServiceImpl extends BaseServiceImpl implements ICompanyService {

	@Autowired
	private ICompanyDao companyDaoImpl;
	
	public int addCompany(CompanyDTO companyDTO) throws SQLException {
		return companyDaoImpl.addComany(companyDTO);
	}

	public int updateCompany(CompanyDTO companyDTO) throws SQLException {
		return companyDaoImpl.updateComany(companyDTO);
	}

	public List<CompanyDTO> listCompany(CompanyDTO companyDTO) {
		return companyDaoImpl.queryComanyList(companyDTO);
	}

	@Override
	public String makeCompanyUser(CompanyInvitationCodeDTO cic) throws SQLException {
		companyDaoImpl.makeComanyUser(cic);
		//生成邀请码
		cic.setCompanyInvitationCode(cic.getCompanyId().toString()+((int)(Math.random()*10000)));
		companyDaoImpl.addCompanyInvitationCode(cic);
		return cic.getCompanyInvitationCode();
	}

}
